//
//  PictureTableViewCell.m
//  ProJectB_1
//
//  Created by 布呐呐 on 16/8/19.
//  Copyright © 2016年 yangshukai. All rights reserved.
//

#import "PictureTableViewCell.h"

@implementation PictureTableViewCell

- (void)setDataWithModel:(PictureModel *)model
{
    //简单直接赋值部分
    //发布者名称
    _userName.text = model.u[@"name"];
    //发布时间
    _passTime.text = model.passtime;
    //发布内容文字
    _contentText.text = model.text;
    NSLog(@"+++++++++++++%@",model.down);
    //赞的个数
    _zanCount.text = model.up;
    //踩的个数
    _caiCount.text = [NSString stringWithFormat:@"%@", model.down];
    //评论的个数
    _pinglunCount.text = model.comment;
    
    
    //取头像图片地址数组的其中一个地址
    NSString *userImgUrl = [model.u[@"header"] lastObject];
    [_UserImage sd_setImageWithURL:[NSURL URLWithString:userImgUrl]];
    
    [_zanBtn setImage:[[UIImage imageNamed:@"zan"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:(UIControlStateNormal)];
    [_caiBtn setImage:[[UIImage imageNamed:@"cai"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:(UIControlStateNormal)];
    [_shareBtn setImage:[[UIImage imageNamed:@"shareBlue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:(UIControlStateNormal)];
    [_pinglunBtn setImage:[[UIImage imageNamed:@"pinlunBlue"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:(UIControlStateNormal)];
#pragma mark ------ 发布图片设置
    
#warning 图片依靠type分为image静态图和gif 动态图
    
    if ([model.type isEqualToString:@"gif"]) {
        CGFloat height = [model.gif[@"height"] floatValue];
        CGFloat width = [model.gif[@"width"] floatValue];
        //判断图片是否过大
        if (height > self.passPicture.bounds.size.height || width > self.passPicture.bounds.size.width) {
            if (height > self.passPicture.bounds.size.height && width <= self.passPicture.bounds.size.width) {
                //当图片高大于默认视图高，保持默认视图高，使视图宽等于图片宽
                _passPicture.width = width;
            }
            if (height <=self.passPicture.bounds.size.height && width > self.passPicture.bounds.size.width) {
                //当图片宽大于默认视图宽，保持默认视图宽，使视图宽等于图片高
                _passPicture.height = height;
            }
        } else {
            _passPicture.height = height;
            _passPicture.width = width;
        }
        [_passPicture sd_setImageWithURL:[model.gif[@"images"] lastObject]];
    
        //图片链接
    }else if ([model.type isEqualToString:@"image"]){
        CGFloat height = [model.image[@"height"] floatValue];
        CGFloat width = [model.image[@"width"] floatValue];
        //判断图片是否过大
        if (height > self.passPicture.bounds.size.height || width > self.passPicture.bounds.size.width) {
            if (height > self.passPicture.bounds.size.height && width <= self.passPicture.bounds.size.width) {
                //当图片高大于默认视图高，保持默认视图高，使视图宽等于图片宽
                _passPicture.width = width;
            }
            if (height <=self.passPicture.bounds.size.height && width > self.passPicture.bounds.size.width) {
                //当图片宽大于默认视图宽，保持默认视图宽，使视图宽等于图片高
                _passPicture.height = height;
            }
            _passPicture.contentMode = UIViewContentModeScaleAspectFit;
            self.contentView.clipsToBounds = YES;
        } else {
            _passPicture.height = height;
            _passPicture.width = width;
        }
        [_passPicture sd_setImageWithURL:[model.image[@"medium"] lastObject]];

    }
    

    
    
 
}

















//

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
